package com.kuang.controller;

import com.kuang.common.anno.IgnoreToken;
import com.kuang.common.limit.annotation.AccessIpLimiter;
import com.kuang.entity.Product;
import com.kuang.service.product.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProductController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(ProductController.class);

    @Autowired
    private ProductService productService;

    @GetMapping("/product/list")
    @AccessIpLimiter(limit = 5, timeout = 1)
    public List<Product> productList(int pageNo,int pageSize) {
        log.info("你输入的参数是：{}，{}",pageNo,pageSize);
        return productService.list();
    }


    @GetMapping("/product/get/{id}")
    @AccessIpLimiter(limit = 5, timeout = 1)
    @IgnoreToken
    public Product getProduct(@PathVariable("id") Long id) {
        return productService.getById(id);
    }


    @PostMapping("/product/save")
    public String saveProduct1(Product product){
        log.info("保存进来了",product);
        return "success";
    }

    @PostMapping("/product/save2")
    public String saveProduct2(@RequestBody  Product product){
        log.info("保存进来了",product);
        return "success";
    }
}
